﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace ProjectN.Core.Element.Def
{
    [JsonObject]
    [DataContract]
    [TypeConverter(typeof(ExpandableObjectConverter))]
    public record class RRectangle(System.Drawing.Rectangle rect)
    {
        private System.Drawing.Rectangle rect = rect;

        [DisplayName("X 坐标")]
        [DataMember] public int X { get => rect.X; set => rect.X = value; }

        [DisplayName("Y 坐标")]
        [DataMember] public int Y { get => rect.Y; set => rect.Y = value; }

        [DisplayName("高度")]
        [DataMember] public int H { get => rect.Height; set => rect.Height = value; }

        [DisplayName("宽度")]
        [DataMember] public int W { get => rect.Height; set => rect.Height = value; }
        [Browsable(false)] public Point Position { get => rect.Location; set => rect.Location = value; }
        [Browsable(false)] public System.Drawing.Size Size { get => rect.Size; set => rect.Size = value; }
        [Browsable(false)] public System.Drawing.Rectangle Rect { get => rect; }

        public RRectangle(): this(new System.Drawing.Rectangle()) { }
        public static implicit operator RRectangle(System.Drawing.Rectangle rect)
            => new(rect);
        public static implicit operator System.Drawing.Rectangle(RRectangle rect)
            => rect.Rect;

        public override string ToString()
            => string.Format($"坐标({X}, {Y}) 大小({W}, {H})");
    }

    [JsonObject]
    [DataContract]
    [TypeConverter(typeof(ExpandableObjectConverter))]
    public record class RRectangleF(RectangleF rect)
    {
        private RectangleF rect = rect;

        [DisplayName("X 坐标")]
        [DataMember] public float X { get => rect.X; set => rect.X = value; }

        [DisplayName("Y 坐标")]
        [DataMember] public float Y { get => rect.Y; set => rect.Y = value; }

        [DisplayName("高度")]
        [DataMember] public float H { get => rect.Height; set => rect.Height = value; }

        [DisplayName("宽度")]
        [DataMember] public float W { get => rect.Width; set => rect.Width = value; }
        [Browsable(false)] public PointF Location { get => rect.Location; set => rect.Location = value; }
        [Browsable(false)] public System.Drawing.SizeF Size { get => rect.Size; set => rect.Size = value; }
        [Browsable(false)] public RectangleF Rect { get => rect; }

        public RRectangleF() : this(new RectangleF()) { }
        public static implicit operator RRectangleF(RectangleF rect)
            => new(rect);
        public static implicit operator RectangleF(RRectangleF rect)
            => rect.Rect;

        public override string ToString()
            => string.Format($"坐标({X}, {Y}) 大小({W}, {H})");
    }

    [JsonObject]
    [method: JsonConstructor]
    public record class RColor(int ARGB)
    {
        public static implicit operator RColor(Color color)
            => new(color.ToArgb());
        public static implicit operator Color(RColor color)
            => Color.FromArgb(color);
        public static implicit operator int(RColor color)
            => color.ARGB;
        public static implicit operator RColor(int color)
            => new(color);
        public static implicit operator RColor(uint color)
            => new((int)color);
    }
}
